<template>
  <div ref="chart" style="width: 196px; height: 155px;"></div>
</template>
 
<script>
import * as echarts from 'echarts';
 
export default {
  name: 'MyChart',
  mounted() {
    this.initChart();
  },
  methods: {


    

    initChart() {
      // 获取DOM元素
      const chartDom = this.$refs.chart;
      
      // 初始化ECharts实例
      const myChart = echarts.init(chartDom);
 
      // 配置图表选项
      let myData3 = [
        "11-14",
        "11-15",
        "11-16",
        "11-17",
        "11-18",
        "11-19",
        "11-20",
      ];
      let numA = [350, 250, 320, 420, 380, 180, 280];
      let xse = [300, 200, 280, 350, 320, 150, 250];
      let option = {
        backgroundColor: "#011a38",
        tooltip: {
          show: true,
          trigger: "axis",
          axisPointer: {
            type: "shadow",
            textStyle: {
              color: "#fff",
            },
          },
          textStyle: {
            color: "#fff",
          },
          backgroundColor: "rgba(16, 123, 184, .52)", //设置背景颜色
          confine: true,
        },
        grid: {
          top: "16%",
          left: "2%",
          right: "2%",
          bottom: "4%",
          containLabel: true,
        },
        legend: {
          top: "0%",
          y: "center",
          itemWidth: 14,
          itemHeight: 4,
          itemGap: 20,
          textStyle: {
            fontSize: 12,
            color: "#fff",
            padding: [0, 0, 0, 6],
          },
        },
        xAxis: [
          {
            type: "category",
            axisLine: {
              lineStyle: {
                color: "#ffffff",
              },
            },
            splitLine: {
              show: false,
            },
            axisTick: {
              show: false,
            },
            splitArea: {
              show: false,
            },
            axisLabel: {
              interval: 0,
            },
            axisLine: {
              show: false,
              lineStyle: {
                color: "#ffffff",
              },
            },
            data: myData3,
          },
        ],
        yAxis: [
          {
            type: "value",
            name: "销量 / 单",
            splitNumber: 5,
            nameTextStyle: {
              color: "#fff",
              fontSize: 12,
              align: "center",
              padding: [0, 20, 5, 0],
            },
            axisLabel: {
              formatter: "{value}",
              color: "rgba(95, 187, 235, 1)",
              textStyle: {
                fontSize: 14,
                color: "#fff",
                lineHeight: 16,
              },
            },
            axisTick: {
              show: false,
            },
            splitLine: {
              show: true,
              lineStyle: {
                color: "rgba(28, 130, 197, .3)",
                type: "dashed",
              },
            },
          },
          {
            name: "增长额 / 万元",
            splitNumber: 5,
            type: "value",
            nameTextStyle: {
              color: "#fff",
              fontSize: 12,
              align: "center",
              padding: [0, 0, 5, 0],
            },
            axisLabel: {
              show: true,
              fontSize: 12,
              color: "#fff",
            },
            axisLine: {
              show: false,
            },
            axisTick: {
              show: false,
            },
            splitLine: {
              show: false,
            },
          },
        ],
        series: [
          {
            name: "销量",
            type: "bar",
            stack: "总量",
            barMaxWidth: 24,
            barGap: "10%",
            itemStyle: {
              normal: {
                show: true,
                color: new echarts.graphic.LinearGradient(
                  0,
                  0,
                  0,
                  1,
                  [
                    {
                      offset: 0,
                      color: "#015CC7",
                    },
                    {
                      offset: 1,
                      color: "#031E3E",
                    },
                  ],
                  false
                ),
                barBorderRadius: 0,
                label: {
                  show: false,
                  position: "top",
                  color: "#56C1F8",
                  formatter: function (p) {
                    return p.value > 0 ? p.value : "";
                  },
                },
              },
            },
            data: numA,
          },
          {
            name: "销售额",
            yAxisIndex: 1,
            type: "line",
            showSymbol: false,
            symbol: "circle",
            smooth: true,
            symbolSize: 6,
            lineStyle: {
              normal: {
                color: "#1BC7FF",
              },
            },
          
            itemStyle: {
              color: "#1BC7FF",
              borderColor: "rgba(27, 199, 255, 0.30)",
              borderWidth: 6,
              shadowColor: "rgba(27, 199, 255, 0.5)",
              shadowBlur: 6,
              opacity: 1,
            },
            label: {
              show: false,
            },
            data: xse, // 折线图的数据
          },
        ],
      }
 
      // 使用配置项显示图表
      myChart.setOption(option);
    }
  }
};
</script>